﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGGWElevator
{
    /// <summary>
    /// Request invoked by user.
    /// Author: Paweł Iżycki
    /// </summary>
    public class Request : UniqueObject, ICloneable
    {
        Floor requestedFloor = Floor.Undifined;
        Floor startingFloor = Floor.Undifined;
        Direction direction = Direction.Undifined;

        public Floor RequestedFloor { get { return this.requestedFloor; } }
        public Floor StartingFloor { get { return this.startingFloor; } }
        public Direction Direction { get { return this.direction; } }

        // Constructor
        public Request(int uniqueId, Floor startingFloor, Floor requestedFloor, Direction direction)
            : base(uniqueId)
        {
            if (startingFloor == Floor.Undifined ||
                requestedFloor == Floor.Undifined ||
                direction == Direction.Undifined)
                throw new UndifinedFloorException();
            else
            {
                this.requestedFloor = requestedFloor;
                this.startingFloor = startingFloor;
                this.direction = direction;
            }
        }



        #region Operators
        public static bool operator ==(Request r1, Request r2)
        {
            if (object.Equals(r1, null) && object.Equals(r2, null))
                return true;

            if (object.Equals(r1, null) || object.Equals(r2, null))
                return false;

            return
                (r1.uniqueId == r2.uniqueId) ||
                (r1.requestedFloor == r2.requestedFloor && r1.startingFloor == r2.startingFloor);
        }

        public static bool operator !=(Request r1, Request r2)
        {
            return !(r1 == r2);
        }
        #endregion

        /// <summary>
        /// Makes deep copy of the object with diffrent UniqueID.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return new Request(UniqueIdGenerator.GetUniqueId(), this.startingFloor, this.requestedFloor, this.direction);
        }

        public override string ToString()
        {
            return string.Format("Request ID: {0}, requested floor: {1}, starting floor: {2}, direction: {3}", this.uniqueId, this.RequestedFloor, this.StartingFloor, this.Direction);
        }
    }
}
